/*import java.util.*;
public class JavaApplication2 {
    public static void main(String[] args) {
      Scanner reader=new Scanner(System.in);
      int b;
      System.out.println("请输入任意一位正整数：");
      b=reader.nextInt();
      int a[]=new int[b];
      for(int i=0;i<b;i++)
          System.out.println(" "+a[i]);
    }
    
}*/
/*import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class JavaApplication2{
    public static void main(String[] args){
        JFrame jfm=new JFrame("java实验");
        jfm.setBounds(200,100,400,200);
        FlowLayout flow=new FlowLayout(FlowLayout.CENTER,10,10);
        //FlowLayout flow=new FlowLayout(FlowLayout.LEFT,5,5);
        //FlowLayout flow=new FlowLayout(FlowLayout.RIGHT,5,5);
        //FlowLayout flow=new FlowLayout(FlowLayout.LEADING,5,5);
        jfm.setLayout(flow);
        JButton jbt=new JButton("按钮");
        jbt.setBounds(0,0,100,10);
        JLabel jlb=new JLabel("标签");
        jlb.setBounds(0,10,100,10);
        JPasswordField jpf=new JPasswordField("你好",10);
        jpf.setBounds(0,20,100,10);
        jbt.setToolTipText("这是一个按钮");
        jlb.setToolTipText("这是一个标签");
        jpf.setToolTipText("这是一个密码框");
        jfm.add(jbt);
        jfm.add(jlb);
        jfm.add(jpf);
        jfm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //jfm.setResizable(false);
        jfm.setVisible(true);
    }
}*/
/*import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class JavaApplication2 extends JFrame{
    JTextField jtf=new JTextField("该文本不可编辑",30);
    static JPasswordField jpf=new JPasswordField("太空人3号",30);
    public JavaApplication2(String str){
        super(str);
        jtf.setBounds(20,40,140,20);
        jtf.setEditable(false);
        this.add(jtf);
    }
    public static void main(String[] args){
        JavaApplication2 frm=new JavaApplication2("文本功能编辑窗口");
        JTextArea jta=new JTextArea("您好",10,30);
        JScrollPane jsp=new JScrollPane(jta);
        frm.setLocation(200,150);
        frm.setSize(240,220);
        frm.setLayout(null);
        jsp.setBounds(20,70,160,100);
        jpf.setBounds(20,10,140,20);
        frm.add(jsp);
        frm.add(jpf);
        char[] password=jpf.getPassword();
        String str=new String(password);
        JOptionPane.showMessageDialog(null,str);
        System.out.println("今天的口令是："+password+"转换成文本后是："+str);
        frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frm.setResizable(false);
        frm.setVisible(true);
    }
}*/
/*import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JavaApplication2 extends JFrame{
    public JavaApplication2(String str){
        super(str);
        //this.setLayout(new BorderLayout(5,10));注：steLayout函数摆放的位置决定框架的布局，此程序中有三处
        JButton jbt1=new JButton("按钮1");
        this.add(jbt1,BorderLayout.SOUTH);
        //this.setLayout(new BorderLayout(5,10));
    }
    public static void main(String[] args){
       JavaApplication2 app=new JavaApplication2("布局管理器");
       app.setLocation(200,300);
       app.setSize(400,200);
       //app.setLayout(new BorderLayout());
       JButton jbt5=new JButton("按钮5");
       JButton jbt2=new JButton("按钮2");
       JButton jbt3=new JButton("按钮3");
       JButton jbt4=new JButton("按钮4");
       app.add(jbt2,BorderLayout.NORTH);
       app.add(jbt3,BorderLayout.WEST);
       app.add(jbt4,BorderLayout.EAST);
       app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       app.setVisible(true);
    }
}*/
/*import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JavaApplication2 extends JFrame {
    static JButton jbt=new JButton("按钮");
    
    public JavaApplication2(String str){
        super(str);
    }
    public static void main(String[] args){
        JavaApplication2 app=new JavaApplication2("cc");
        app.setLocation(100,150);
        app.setSize(200,250);
        app.setLayout(null);
        jbt.setBounds(0,0,200,30);
        jbt.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
             app.getContentPane().setBackground(Color.YELLOW);
       }
        });
        app.add(jbt);
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        app.setVisible(true);
    }
}*/
/*import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JavaApplication2 extends JFrame implements ActionListener {
    static JButton jbt=new JButton("按钮");
    public JavaApplication2(String str){
        super(str);
        jbt.addActionListener(this);
    }
    
    static JavaApplication2 app=new JavaApplication2("cc");
    
    public void actionPerformed(ActionEvent e){
        app.getContentPane().setBackground(Color.red);
    }
    public static void main(String[] args){
        app.setLocation(100,150);
        app.setSize(200,250);
        app.setLayout(null);
        jbt.setBounds(0,0,200,30);
        //jbt.addActionListener(app);
        app.add(jbt);
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        app.setVisible(true);
    }
}*/
/*class Cylinder   //定义圆柱体类Cylinder
{
    double radius;     //声明成员变量radius
    int height;        //声明成员变量height
    double pi=3.14;   //声明数据成员pi并赋初值
    static int count=0;
    
    public Cylinder(){
        count++;
    }
    
    public Cylinder(double radius,int height){
        this.radius=radius;
        this.height=height;
        count++;
    }
    void area( ) 
    {
          System.out.println("圆柱底面积="+ pi*radius* radius);
      }
     void volume( ) 
      {
         System.out.println("圆柱体体积="+((pi*radius* radius)*height));
      }
}
public class JavaApplication2{
public static void main(String[] args){
      Cylinder a=new Cylinder();
      Cylinder b=new Cylinder(1.0,1);
      Cylinder c=new Cylinder();
      System.out.println("count="+a.count);
  }
}*/
/*import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class App14_1 extends JFrame{
    static JButton bnt1=new JButton("按钮");
    static JButton bnt2=new JButton("画椭圆");
    static JPanel pan=new MyPanel();
    static App14_1 frm=new App14_1();
    static int circle=0;
    
    public static void main(String[] args){
    frm.setTitle("简单绘图应用程序");
    frm.setSize(300,250);
    frm.setLayout(null);
    pan.setBounds(0,0,300,250);
    frm.add(pan);
    frm.setVisible(true);
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    static  class MyPanel extends JPanel implements ActionListener{
        public MyPanel(){
            bnt1.addActionListener(this);bnt2.addActionListener(this);
            this.add(bnt1);this.add(bnt2);
        }
        
        public void actionPerformed(ActionEvent e){
            JButton bt=(JButton)e.getSource();
            if(bt==bnt1) circle=1;
            else circle=2;
            //Graphics g=this.getGraphics();
            repaint();
         }
        
        public void paintComponent(Graphics g){
            super.paintComponent(g);
            bnt1.setBounds(50,180,80,25);
            bnt2.setBounds(150,180,80,25);
            g.setFont(new Font("楷体",Font.ITALIC,20));
            g.setColor(Color.red);
            g.drawString("画图或画圆",120,30);
            if(circle==1)
                g.drawOval(100,70,70,70);
            else g.drawOval(80,40,70,120);
        }
    }
}*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class App13_5 extends JFrame implements ItemListener{
    static App13_5 frm=new App13_5();
    static JCheckBox chk1=new JCheckBox("粗体");
    static JCheckBox chk2=new JCheckBox("斜体");
    static JRadioButton rb1=new JRadioButton("红色");
    static JRadioButton rb2=new JRadioButton("蓝色");
    static JTextArea ta=new JTextArea("选项事件类ItemEvent的使用方法",8,30);
    public static void main(String[] args){
        ButtonGroup grp=new ButtonGroup();
        frm.setTitle("选项事件处理");
        frm.setLocation(200,150);
        frm.setSize(260,220);
        frm.setLayout(new FlowLayout(FlowLayout.LEFT));
        grp.add(rb1);
        grp.add(rb2);
        chk1.addItemListener(frm);
        chk2.addItemListener(frm);
        rb1.addItemListener(frm);
        rb2.addItemListener(frm);
        frm.add(chk1);frm.add(chk2);frm.add(rb1);frm.add(rb2);frm.add(ta);
        frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frm.setVisible(true);
    }

    public void itemStateChanged(ItemEvent e){
        Font font1=ta.getFont();
        int style1=font1.getStyle();
        if(rb1.isSelected()) ta.setForeground(Color.RED);
        if(rb2.isSelected()) ta.setForeground(Color.BLUE);
        if(e.getSource()==chk1||e.getSource()==chk2){
            if((JCheckBox)e.getSource()==chk1) style1=style1+1;
            if((JCheckBox)e.getSource()==chk2) style1=style1+2;
            ta.setFont(new Font(font1.getName(),style1,font1.getSize()));
            ta.append("\n样式style="+style1+";"+"状态="+e.getStateChange()+"[1:选中2:取消]");
      }
   }
}
